﻿<Window
        x:Class="TVGrid.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:asp="clr-namespace:TVGrid"
        xmlns:vm="clr-namespace:TVGrid.ViewModel"
        Title="MainWindow" Height="450" Width="600" Background="#FF373434">

    <Window.Resources>
        <Style TargetType="TextBlock">
            <Setter Property="Foreground" Value="White"/>
            <Setter Property="FontSize" Value="16"/>
            <Setter Property="Margin" Value="2,3,3,2"/>
        </Style>
        <vm:VisibilityConverter x:Key="LoginConverter"/>
    </Window.Resources> 

    <Grid x:Name="MainGrid">
        <Grid.RowDefinitions>
            <RowDefinition Height="auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <!-- Tv frames -->
        <ListView x:Name="listView"
                  SelectionMode="Extended"
                  ItemsSource="{Binding Path=UserStations}" 
                  SelectedValue="{Binding Path=SelectedTVFromList}"
                  Background="Transparent" 
                  Grid.Row="1"
                  ScrollViewer.HorizontalScrollBarVisibility="Disabled"
                  ScrollViewer.VerticalScrollBarVisibility="Disabled"
                  >
            <ListView.ItemsPanel>
                <ItemsPanelTemplate>
                    <asp:AutoSizePanel VerticalAlignment="Center" HorizontalAlignment="Center" Width="{Binding ElementName=listView, Path=ActualWidth}" Height="{Binding ElementName=listView, Path=ActualHeight}"  x:Name="TVContainer" IsItemsHost="True" />
                </ItemsPanelTemplate>
            </ListView.ItemsPanel>
            <ListView.ItemContainerStyle>
                <Style TargetType="ListViewItem">
                    <Setter Property="VerticalContentAlignment" Value="Center" />
                    <Setter Property="HorizontalContentAlignment" Value="Center" />
                    <Style.Resources>
                        <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="CornflowerBlue"/>
                        <SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="CornflowerBlue"/>
                    </Style.Resources>
                </Style>
            </ListView.ItemContainerStyle>
            <ListView.ItemTemplate>
                <DataTemplate>
                    <Grid Margin="5">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="auto"/>
                            <RowDefinition Height="*"/>
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="auto"/>
                            <ColumnDefinition Width="*"/>
                        </Grid.ColumnDefinitions>

                        <TextBlock Grid.Column="0" Text="{Binding Path=StationName}" Foreground="#FFF9F000" FontSize="13.333"/>
                        <Border Grid.ColumnSpan="2" Grid.Row="1" BorderBrush="BlueViolet" BorderThickness="2" >
                            <MediaElement x:Name="mediaobject" Source="{Binding Path=Address}" Volume="{Binding Path=Volume}" VerticalAlignment="Bottom" >
                                <MediaElement.ToolTip>
                                    <ToolTip>You can unselect a tv by holding 
                                        ctrl key whill clicking</ToolTip>
                                </MediaElement.ToolTip>
                            </MediaElement>
                        </Border>
                    </Grid>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>

        <!-- Main manu -->
        <Grid Background="BlueViolet">
            <Grid.Effect>
                <DropShadowEffect Direction="240"/>
            </Grid.Effect>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            
            <Menu Grid.Row="0" Grid.Column="0">
                <MenuItem Header="Stations">
                    <MenuItem Header="Add station" Height="auto">
                        <MenuItem>
                            <MenuItem.Template>
                                <ControlTemplate TargetType="MenuItem" >
                                    
                                    <Grid>
                                        <Grid.RowDefinitions>
                                            <RowDefinition Height="auto"/>
                                        </Grid.RowDefinitions>
                                        <Border Grid.Row="0" BorderThickness="2" Margin="0" BorderBrush="White">
                                            <Border.Effect>
                                                <DropShadowEffect Color="Black" BlurRadius="5" />
                                            </Border.Effect>
                                            <Grid Background="#FF373434">
                                                <Grid.DataContext>
                                                    <vm:NewStationViewModel/>
                                                </Grid.DataContext>
                                                <Grid.RowDefinitions>
                                                    <RowDefinition Height="auto" />
                                                    <RowDefinition Height="auto" />
                                                    <RowDefinition Height="*" />
                                                </Grid.RowDefinitions>
                                                <Grid.ColumnDefinitions>
                                                    <ColumnDefinition Width="Auto" />
                                                    <ColumnDefinition Width="*" />
                                                </Grid.ColumnDefinitions>
                                                <TextBlock Grid.Row="0" Grid.Column="0" Text="Name" Foreground="White"/>
                                                <TextBox Grid.Row="0" Margin="2,3,3,2" Grid.Column="1" Width="150" MaxWidth="150" Text="{Binding  Path=Name, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True, NotifyOnValidationError=True}" />
                                                <TextBlock Grid.Row="1" Grid.Column="0" Text="URL" Foreground="White"/>
                                                <TextBox  Margin="2,3,3,2" Grid.Row="1" Grid.Column="1" Width="150" MaxWidth="150" Text="{Binding  Path=URL, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True, NotifyOnValidationError=True}" />
                                                <DockPanel Grid.Row="3" Grid.ColumnSpan="2">
                                                    <TextBlock Text="{Binding Path=ErrorMag}" ToolTip="{Binding Path=ErrorMagTT}" HorizontalAlignment="Left" Foreground="Red" FontSize="15" VerticalAlignment="Bottom"/>
                                                    <StackPanel Orientation="Horizontal" Height="28" HorizontalAlignment="Right">
                                                        <Button Content=" Add " Command="{Binding Path=AddStationCommand}" Margin="3" Padding="2" />
                                                    </StackPanel>
                                                </DockPanel>
                                            </Grid>
                                        </Border>
                                    </Grid>
                                </ControlTemplate>
                            </MenuItem.Template>
                        </MenuItem>
                    </MenuItem>
                    <MenuItem Header="Stations" ItemsSource="{Binding TvStasions}">
                        <MenuItem.ItemContainerStyle>
                            <Style TargetType="MenuItem">
                                <Setter Property="Template">
                                    <Setter.Value>
                                        <ControlTemplate>
                                            <MenuItem Header="{Binding Path=StationName}">
                                                <MenuItem Header="Watch" Click="MenuItemAddUserStationClick" />
                                                <MenuItem Header="Remove from list" Click="MenuItemRemoveStationClick" />
                                            </MenuItem>
                                        </ControlTemplate>
                                    </Setter.Value>
                                </Setter>
                            </Style>
                        </MenuItem.ItemContainerStyle>
                    </MenuItem>
                </MenuItem>
                <MenuItem Header="Control">
                    <MenuItem Header="Volume">
                        <MenuItem>
                            <MenuItem.Template>
                                <ControlTemplate>
                                    <Slider Name="VolumeSlider"  MinWidth="100" MaxWidth="200" DataContext="{Binding SelectedTVFromList}" Value="{Binding Path=Volume, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Minimum="0" Maximum="1"/>
                                </ControlTemplate>
                            </MenuItem.Template>
                        </MenuItem>
                    </MenuItem>
                    <MenuItem Header="Remove" Command="{Binding Path=RemovUserStationCommand}"/>
                </MenuItem>
                <MenuItem Header="Login">
                    <MenuItem.DataContext>
                        <vm:LoginViewModel/>
                    </MenuItem.DataContext>
                        <MenuItem Height="auto" Visibility="{Binding Path=ShowLogin,Converter={StaticResource ResourceKey=LoginConverter}, ConverterParameter=login}">
                            <MenuItem.Template>
                                <ControlTemplate>
                                    <Grid>
                                        <Grid.RowDefinitions>
                                            <RowDefinition Height="auto"/>
                                        </Grid.RowDefinitions>
                                        <Border Grid.Row="0" BorderThickness="2" Margin="0" Padding="2" BorderBrush="White"  >
                                            <Border.Effect>
                                                <DropShadowEffect Color="Black" BlurRadius="5" />
                                            </Border.Effect>
                                            <Grid Background="#FF373434">
                                                <Grid.RowDefinitions>
                                                    <RowDefinition Height="auto" />
                                                    <RowDefinition Height="auto" />
                                                    <RowDefinition Height="*" />
                                                </Grid.RowDefinitions>
                                                <Grid.ColumnDefinitions>
                                                    <ColumnDefinition Width="Auto" />
                                                    <ColumnDefinition Width="*" />
                                                </Grid.ColumnDefinitions>
                                                <TextBlock Grid.Row="0" Grid.Column="0" Text="Name" Foreground="White"/>
                                                <TextBox Grid.Row="0" Margin="2,3,3,2" Grid.Column="1" Width="150" MaxWidth="150" Text="{Binding  Path=UserName, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True, NotifyOnValidationError=True}" />
                                                <TextBlock Grid.Row="1" Grid.Column="0" Text="Password" Foreground="White"/>
                                                <PasswordBox Name="Password" Margin="2,3,3,2" Grid.Row="1" Grid.Column="1" Width="150" MaxWidth="150"/>
                                                <DockPanel Grid.Row="3" Grid.ColumnSpan="2">
                                                    <TextBlock Text="{Binding Path=ErrorMag}" ToolTip="{Binding Path=ErrorMagTT}" HorizontalAlignment="Left" Foreground="Red" FontSize="15" VerticalAlignment="Bottom"/>
                                                    <StackPanel Orientation="Horizontal" Height="28" HorizontalAlignment="Right">
                                                        <Button Content="Register" Command="{Binding Path=RegisterCommand}" CommandParameter="{Binding ElementName=Password}" Margin="3" Padding="2" />
                                                        <Button Content="Login" Command="{Binding Path=LoginCommand}" CommandParameter="{Binding ElementName=Password}" Margin="3" Padding="2" />
                                                    </StackPanel>
                                                </DockPanel>
                                            </Grid>
                                        </Border>
                                    </Grid>
                                </ControlTemplate>
                            </MenuItem.Template>
                        </MenuItem>
                        <MenuItem Header="Logout" Command="{Binding Path=LogoutCommand}" Visibility="{Binding Path=ShowLogin,Converter={StaticResource ResourceKey=LoginConverter}, ConverterParameter=logout}"/>
                    </MenuItem>
            </Menu>
        </Grid>
    </Grid>
</Window>
